package com.cli.spring_session_demo.exceptions;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.util.Locale;

/**
 * Created by work on 2017/5/31.
 * <p>
 * Exceptions thrown by service or spring can be handled at here and custom the response.
 * <p>
 * exception handlers
 */
@ControllerAdvice
public class APIExceptionHandler extends ResponseEntityExceptionHandler {
    private final Locale currentLocale = LocaleContextHolder.getLocale();
    /**
     * @ExceptionHandler({Exception.class}) public ResponseEntity<?> commonExceptionHandler(Exception e, WebRequest request) {
     * return ResponseEntity.status(HttpStatus.NOT_FOUND).body(((APIException)e).toJSON());
     * }
     **/

    @Autowired
    private MessageSource messageSource;

//    @ExceptionHandler({ObjectNotFoundException.class})
//    public ResponseEntity<?> notFoundExceptionHandler(Exception e, WebRequest request) {
//        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(((APIException) e).toJSON());
//    }

}
